package com.yuanlrc.hotel.rate.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yuanlrc.common.annotation.Log;
import com.yuanlrc.common.enums.BusinessType;
import com.yuanlrc.hotel.rate.domain.Rate;
import com.yuanlrc.hotel.rate.service.IRateService;
import com.yuanlrc.common.core.controller.BaseController;
import com.yuanlrc.common.core.domain.AjaxResult;
import com.yuanlrc.common.utils.poi.ExcelUtil;
import com.yuanlrc.common.core.page.TableDataInfo;

/**
 * 评分Controller
 * 
 * @author yuanlrc
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/hotel/rate")
public class RateController extends BaseController
{
    private String prefix = "hotel/rate";

    @Autowired
    private IRateService rateService;

    @RequiresPermissions("hotel:rate:view")
    @GetMapping()
    public String rate()
    {
        return prefix + "/rate";
    }

    /**
     * 查询评分列表
     */
    @RequiresPermissions("hotel:rate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Rate rate)
    {
        startPage();
        List<Rate> list = rateService.selectRateList(rate);
        return getDataTable(list);
    }

    /**
     * 导出评分列表
     */
    @RequiresPermissions("hotel:rate:export")
    @Log(title = "评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Rate rate)
    {
        List<Rate> list = rateService.selectRateList(rate);
        ExcelUtil<Rate> util = new ExcelUtil<Rate>(Rate.class);
        return util.exportExcel(list, "rate");
    }

    /**
     * 新增评分
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评分
     */
    @RequiresPermissions("hotel:rate:add")
    @Log(title = "评分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Rate rate)
    {
        return toAjax(rateService.insertRate(rate));
    }

    /**
     * 修改评分
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Rate rate = rateService.selectRateById(id);
        mmap.put("rate", rate);
        return prefix + "/edit";
    }

    /**
     * 修改保存评分
     */
    @RequiresPermissions("hotel:rate:edit")
    @Log(title = "评分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Rate rate)
    {
        return toAjax(rateService.updateRate(rate));
    }

    /**
     * 删除评分
     */
    @RequiresPermissions("hotel:rate:remove")
    @Log(title = "评分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rateService.deleteRateByIds(ids));
    }
}
